#include "start_up.h"
#include "statusbar_view.h"

#include "page.h"
#include <stdio.h>
#include <stdlib.h>

static startup_t start_up;

#if 0
static void start_event_cb(lv_event_t * event)
{
		lv_obj_t* obj = lv_event_get_current_target(event);
    page_base_t* base = (page_base_t*)lv_event_get_user_data(event);

    if (base == NULL)
    {
        return;
    }
	
		lv_event_code_t eventCode = lv_event_get_code(event);
    if (eventCode == LV_EVENT_CLICKED)
    {
       
    }
}
#endif

static void on_timer_update_cb(lv_timer_t* timer)
{
		//page_base_t* base = (page_base_t*)timer->user_data;
		page_start("dialplate");
}


static void on_custom_attr_config(page_base_t *self)
{
    //ESP_LOGI(tag, "on custom attr config");
		page_set_custom_auto_cache_enable(self, false);
		//page_set_custom_root_event_cb(self, start_event_cb);
	  page_set_custom_load_anim_type(self, LOAD_ANIM_NONE, 0, lv_anim_path_overshoot);
}

/* Page load */
static void on_view_load(page_base_t *self)
{
	//ESP_LOGI(tag, "on view load");
	start_up.startup_view = startup_view_create(self->root);
	lv_timer_t* timer = lv_timer_create(on_timer_update_cb, 1500, self);
	lv_timer_set_repeat_count(timer, 1);
}

/* Page load complete */
static void on_view_did_load(page_base_t *self)
{
    //ESP_LOGI(tag, "on view did load");
}

/* Page will be displayed soon  */
static void on_view_will_appear(page_base_t *self)
{
	lv_anim_timeline_start(start_up.startup_view.anim_timeline);
	//lv_obj_fade_in(self->root, 500, 1500);
}

/* The page is displayed  */
static void on_view_did_appear(page_base_t *self)
{
    //ESP_LOGI(tag, "on view did appear");
}

/* Page is about to disappear */
static void on_view_will_disappear(page_base_t *self)
{
    //ESP_LOGI(tag, "on view will disappear");
		 lv_obj_fade_out(self->root, 500, 1500);
}

/* Page disappeared complete  */
static void on_view_did_disappear(page_base_t *self)
{
   // ESP_LOGI(tag, "on view did disappear");
		statusbar_appear(1);
}

/* Page uninstall complete  */
static void on_view_did_unload(page_base_t *self)
{
    //ESP_LOGI(tag, "on view did unload");
	startup_view_delete(&start_up.startup_view);
}

static page_vtable_t page_param = {
    .on_custom_attr_config = on_custom_attr_config,
    .on_view_load = on_view_load,
    .on_view_did_load = on_view_did_load,
    .on_view_will_appear = on_view_will_appear,
    .on_view_did_appear = on_view_did_appear,
    .on_view_will_disappear = on_view_will_disappear,
    .on_view_did_disappear = on_view_did_disappear,
    .on_view_did_unload = on_view_did_unload,
};

page_vtable_t* startup_create(const char *name)
{

    start_up.page_param = &page_param;
    start_up.name = name;

    return start_up.page_param;
}


